begintownscript;

variables;
short bmessage,pcs,seated,leadchar,rctx,rcty;
string custom_m;

body;

beginstate INIT_STATE;
	turn_off_training(1);

	if(get_flag(45,0) == 3){
		force_instant_terrain_redraw();
		reset_dialog();
		add_dialog_str(0,"Holy hell-- what is THIS?",0);
		add_dialog_str(1,"There's a large, raised dais here, and its center is surrounded by eight large, crystal pillars.",0);
		if(get_highest_skill(42) >= 16)
			add_dialog_str(2,"There's a portal in the center of the dais, but that doesn't explain the presence of the crystals.  It could simply be a very long-distance portal, but even those don't require THIS much power.",0);
		else
			add_dialog_str(2,"There's a large, glowing, door-shaped, magical blob at the center of the dais.  Perhaps it's one of those _portal_ devices that magi are so keen on using nowadays.  If this individual can make one, he must be powerful.",0);
		if(party_size() == 1)
			add_dialog_str(3,"But why does this wizard want me?  Nevermind that, why does someone powerful like him want my help in clearing out the brigands?",0);
		if(party_size() == 1)
			add_dialog_str(3,"But why does this wizard want us?  Nevermind that, why does someone powerful like him want our help in clearing out the brigands?",0);
		add_dialog_choice(0,"Hm...");
		bmessage = run_dialog(1);
		set_flag(45,0,4);
	}

	if(get_flag(65,0) >= 9){
		set_terrain(16,12,358);
		set_terrain(16,20,358);
		set_terrain(12,16,358);
		set_terrain(20,16,358);
		set_terrain(13,13,358);
		set_terrain(19,19,358);
		set_terrain(13,19,358);
		set_terrain(19,13,358);
		set_terrain(16,16,137);
		set_terrain(15,16,0);
		set_terrain(17,16,0);
		set_terrain(16,15,0);
		set_terrain(16,17,0);
		force_instant_terrain_redraw();
		reset_dialog();
		if(get_flag(65,0) == 9){
			march_party(16,16);
			march_party(15,16);
			march_party(14,16);
			march_party(13,16);
			force_view_center(13,16);
			force_instant_terrain_redraw();
			if(party_size() == 1){
				if(get_flag(64,0) == 0)
					add_dialog_str(0,"The portal...  It's gone.  Looks like the mysterious figure does not want me back for now.",0);
				else
					add_dialog_str(0,"The portal...  It's gone.  Looks like _K_ does not want me back for now.",0);
			}
			if(party_size() > 1){
				if(get_flag(64,0) == 0)
					add_dialog_str(0,"The portal...  It's gone.  Looks like the mysterious figure does not want us back for now.",0);
				else
					add_dialog_str(0,"The portal...  It's gone.  Looks like _K_ does not want us back for now.",0);
			}
			add_dialog_choice(0,"Hmm.");
			bmessage = run_dialog(1);

			toggle_quest(2,1);
			set_flag(65,0,10);
		}
	}

break;

beginstate EXIT_STATE;
break;

beginstate START_STATE;
break;

beginstate 10;

	if(get_flag(65,0) >= 9)
		end();
	if(is_combat() == TRUE){
		block_entry(1);
		end();
	}
	reset_dialog();
	if(get_highest_skill(42) < 16){
		if(party_size() == 1)
			add_dialog_str(0,"The portal is sitting here, if I'm _brave_ enough to enter...",0);
		if(party_size() > 1)
			add_dialog_str(0,"The portal is sitting here, if we're _brave_ enough to enter...",0);
	}
	else{
		if(party_size() == 1)
			add_dialog_str(0,"The portal is sitting here, waiting for me to step through it.",0);
		if(party_size() > 1)
			add_dialog_str(0,"The portal is sitting here, waiting for us to step through it.",0);
	}
	add_dialog_choice(0,"Don't enter.");
	add_dialog_choice(1,"Enter.");
	bmessage = run_dialog(1);
	if(bmessage == 1){
		block_entry(1);
		end();
	}
	set_total_visibility(1);
	leadchar = 0;
	while(char_ok(leadchar) == FALSE){
		leadchar = (leadchar + 1);
	}
	force_view_center(char_loc_x(leadchar),char_loc_y(leadchar));
	rcty = 0;
	while(rcty <= 31){
		set_terrain(4,rcty,1);
		rcty = (rcty + 1);
	}
	rctx = 0;
	while(rctx <= 31){
		set_terrain(rctx,4,1);
		rctx = (rctx + 1);
	}
	force_view_center(16,16);
	force_instant_terrain_redraw();
	set_terrain(10,3,1);
	set_terrain(11,3,1);
	set_terrain(12,3,1);
	set_terrain(13,3,1);
	set_terrain(3,10,1);
	set_terrain(3,11,1);
	set_terrain(3,12,1);
	set_terrain(3,13,1);
	pcs = 0;
	while(pcs <= 3){
		if(char_ok(pcs) == TRUE){
			put_boom_on_space(char_loc_x(pcs),char_loc_y(pcs), 2,0);
			relocate_character(pcs,1,1);
		}

		pcs = (pcs + 1);
	}
	force_instant_terrain_redraw();
	run_animation_sound(10);
	pause(3);
	move_to_new_town(11,22,22);

break;

